home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / macintosh-c / macc-carbon-demos-nonbinhex.sit / macc-carbon-demos-nonbinhex / chap21-demo-classic events / DateTimeNumbers / DateTimeNumbers.c < prev    next >
C/C++ Source or Header  |  2001-07-17  |  19KB  |  691 lines

  1. // *******************************************************************************************
  2. // DateTimeNumbers.c                                                       CLASSIC EVENT MODEL
  3. // *******************************************************************************************
  4. //
  5. // This program, which opens a single modeless dialog, demonstrates the formatting and display
  6. // of dates, times and numbers.
  7. //
  8. // The program utilises the following resources:
  9. //
  10. // •    A 'plst' resource.
  11. //
  12. // •    An 'MBAR' resource, and 'MENU' resources for Apple/Application, File, and Edit menus 
  13. //        (preload, non-purgeable).
  14. //
  15. // •    A 'DLOG' resource and associated 'dlgx', 'DITL', 'dfnt', and 'CNTL' resources 
  16. //        (purgeable).  
  17. //
  18. // •    'hdlg' and 'STR#' resources (purgeable) for balloon help and help tags. 
  19. //
  20. // •    A 'SIZE' resource with the acceptSuspendResumeEvents, canBackground, 
  21. //        doesActivateOnFGSwitch, and isHighLevelEventAware flags set.
  22. //
  23. // *******************************************************************************************
  24.  
  25. // ………………………………………………………………………………………………………………………………………………………………………………………………………………………… includes
  26.  
  27. #include <Carbon.h>
  28. #include <string.h>
  29.  
  30. // …………………………………………………………………………………………………………………………………………………………………………………………………………………………… defines
  31.  
  32. #define rMenubar                                128
  33. #define mAppleApplication                128
  34. #define  iAbout                                    1
  35. #define mFile                                        129
  36. #define  iQuit                                    12
  37. #define mEdit                                        130
  38. #define  iCut                                        3
  39. #define  iCopy                                    4
  40. #define  iPaste                                    5
  41. #define  iClear                                    6
  42. #define rDialog                                    128
  43. #define  iStaticTextTodaysDate    2
  44. #define  iStaticTextCurrentTime    4
  45. #define  iEditTextTitle                    10
  46. #define  iEditTextQuantity            11
  47. #define  iEditTextValue                    12
  48. #define  iEditTextDate                    13
  49. #define  iButtonEnter                        18
  50. #define  iButtonClear                        19
  51. #define  iStaticTextTitle                26
  52. #define  iStaticTextQuantity        27
  53. #define  iStaticTextUnitValue        28
  54. #define  iStaticTextTotalValue    29
  55. #define  iStaticTextDate                30
  56. #define kReturn                                    0x0D
  57. #define kEnter                                    0x03
  58. #define kTab                                        0x09
  59. #define kLeftArrow                            0x1C
  60. #define kRightArrow                            0x1D
  61. #define kUpArrow                                0x1E
  62. #define kDownArrow                            0x1F
  63. #define kBackspace                            0x08
  64. #define kDelete                                    0x7F
  65. #define topLeft(r)                            (((Point *) &(r))[0])
  66. #define botRight(r)                            (((Point *) &(r))[1])
  67.  
  68. // …………………………………………………………………………………………………………………………………………………………………………………………………… global variables
  69.  
  70. Boolean                    gRunningOnX = false;
  71. DialogRef                gDialogRef;
  72. DateCacheRecord    gDateCacheRec;
  73. Boolean                    gDone;
  74. RgnHandle                gCursorRegionHdl;
  75. Boolean                    gInBackground;
  76.  
  77. // …………………………………………………………………………………………………………………………………………………………………………………………… function prototypes
  78.  
  79. void                                        main                                (void);
  80. void                                        doPreliminaries            (void);
  81. OSErr                                        quitAppEventHandler    (AppleEvent *,AppleEvent *,SInt32);
  82. void                                        eventLoop                        (void);
  83. void                                        doIdle                            (void);
  84. void                                        doEvents                        (EventRecord *);
  85. void                                        doMenuChoice                (SInt32);
  86. void                                        doCopyPString                (Str255,Str255);
  87. void                                        doTodaysDate                (void);
  88. void                                        doAcceptNewRecord        (void);
  89. void                                        doUnitAndTotalValue    (Str255,Str255);
  90. void                                        doDate                            (Str255);
  91. void                                        doAdjustCursor            (WindowRef);
  92. void                                        doClearAllFields        (void);
  93. ControlKeyFilterResult    numericFilter                (ControlRef,SInt16 *,SInt16 *,EventModifiers *);
  94. void                                        helpTags                        (void);
  95.     
  96. // ************************************************************************************** main
  97.  
  98. void  main(void)
  99. {
  100.     MenuBarHandle                menubarHdl;
  101.     SInt32                            response;
  102.     MenuRef                            menuRef;
  103.     Boolean                            runningOnX = false;
  104.     ControlKeyFilterUPP    numericFilterUPP;
  105.     ControlRef                    controlRef;
  106.  
  107.     // ……………………………………………………………………………………………………………………………………………………………………………………………… do preliminaries
  108.  
  109.     doPreliminaries();
  110.  
  111.     // ……………………………………………………………………………………………………………………………………………………………………… set up menu bar and menus
  112.  
  113.     menubarHdl = GetNewMBar(rMenubar);
  114.     if(menubarHdl == NULL)
  115.         ExitToShell();
  116.     SetMenuBar(menubarHdl);
  117.     DrawMenuBar();
  118.  
  119.     Gestalt(gestaltMenuMgrAttr,&response);
  120.     if(response & gestaltMenuMgrAquaLayoutMask)
  121.     {
  122.         menuRef = GetMenuRef(mFile);
  123.         if(menuRef != NULL)
  124.         {
  125.             DeleteMenuItem(menuRef,iQuit);
  126.             DeleteMenuItem(menuRef,iQuit - 1);
  127.             DisableMenuItem(menuRef,0);
  128.         }
  129.  
  130.         gRunningOnX = true;
  131.     }
  132.  
  133.     // …………………………………………………………………………………………………………………………………………………………………………………… open modeless dialog
  134.  
  135.     if(!(gDialogRef = GetNewDialog(rDialog,NULL,(WindowRef) -1)))
  136.         ExitToShell();
  137.  
  138.     // ………… create universal procedure pointers for key filter, attach to two edit text controls
  139.  
  140.     numericFilterUPP = NewControlKeyFilterUPP((ControlKeyFilterProcPtr) numericFilter);
  141.  
  142.     GetDialogItemAsControl(gDialogRef,iEditTextQuantity,&controlRef);
  143.     SetControlData(controlRef,kControlEntireControl,kControlEditTextKeyFilterTag,
  144.                                  sizeof(numericFilterUPP),&numericFilterUPP);
  145.  
  146.     GetDialogItemAsControl(gDialogRef,iEditTextValue,&controlRef);
  147.     SetControlData(controlRef,kControlEntireControl,kControlEditTextKeyFilterTag,
  148.                                  sizeof(numericFilterUPP),&numericFilterUPP);
  149.  
  150.     // ………………………………………………………………………………………………………… set help tags, get today's date, and show window
  151.  
  152.     if(gRunningOnX)
  153.         helpTags();
  154.  
  155.     doTodaysDate();
  156.  
  157.     ShowWindow(GetDialogWindow(gDialogRef));
  158.  
  159.     // ……………………………………………………………………………………………………………………………………………………… initialise date cache structure
  160.  
  161.     InitDateCache(&gDateCacheRec);
  162.  
  163.     // ………………………………………………………………………………………………………………………………………………………………………………………………… enter eventLoop
  164.  
  165.     eventLoop();
  166. }
  167.  
  168. // *************************************************************************** doPreliminaries
  169.  
  170. void  doPreliminaries(void)
  171. {
  172.     OSErr    osError;
  173.  
  174.     MoreMasterPointers(64);
  175.     InitCursor();
  176.     FlushEvents(everyEvent,0);
  177.  
  178.     osError = AEInstallEventHandler(kCoreEventClass,kAEQuitApplication,
  179.                                                         NewAEEventHandlerUPP((AEEventHandlerProcPtr) quitAppEventHandler),
  180.                                                         0L,false);
  181.     if(osError != noErr)
  182.         ExitToShell();
  183. }
  184.  
  185. // **************************************************************************** doQuitAppEvent
  186.  
  187. OSErr  quitAppEventHandler(AppleEvent *appEvent,AppleEvent *reply,SInt32 handlerRefcon)
  188. {
  189.     OSErr            osError;
  190.     DescType    returnedType;
  191.     Size            actualSize;
  192.  
  193.     osError = AEGetAttributePtr(appEvent,keyMissedKeywordAttr,typeWildCard,&returnedType,NULL,0,
  194.                                                             &actualSize);
  195.  
  196.     if(osError == errAEDescNotFound)
  197.     {
  198.         gDone = true;
  199.         osError = noErr;
  200.     } 
  201.     else if(osError == noErr)
  202.         osError = errAEParamMissed;
  203.  
  204.     return osError;
  205. }
  206.  
  207. // ********************************************************************************* eventLoop
  208.  
  209. void  eventLoop(void)
  210. {
  211.     EventRecord    eventStructure;
  212.     Boolean            gotEvent;
  213.     UInt32            sleepTime;
  214.  
  215.     gDone = false;
  216.     sleepTime = GetCaretTime();
  217.     gCursorRegionHdl = NewRgn();
  218.  
  219.     while(!gDone)
  220.     {
  221.         gotEvent = WaitNextEvent(everyEvent,&eventStructure,sleepTime,gCursorRegionHdl);
  222.  
  223.         if(gotEvent)
  224.             doEvents(&eventStructure);
  225.         else
  226.             doIdle();
  227.     }
  228. }
  229.  
  230. // ************************************************************************************ doIdle
  231.  
  232. void  doIdle(void)
  233. {
  234.     UInt32                rawSeconds;
  235.     static UInt32    oldRawSeconds;
  236.     Str255                timeString;
  237.     ControlRef        controlRef;
  238.  
  239.     if(!gRunningOnX)
  240.         IdleControls(GetDialogWindow(gDialogRef));
  241.  
  242.     GetDateTime(&rawSeconds);
  243.  
  244.     if(rawSeconds > oldRawSeconds) 
  245.     {
  246.         TimeString(rawSeconds,true,timeString,NULL);
  247.  
  248.         GetDialogItemAsControl(gDialogRef,iStaticTextCurrentTime,&controlRef);
  249.         SetControlData(controlRef,kControlEntireControl,kControlStaticTextTextTag,timeString[0],
  250.                                      &timeString[1]);
  251.         Draw1Control(controlRef);
  252.  
  253.         oldRawSeconds = rawSeconds;
  254.     }
  255. }
  256.  
  257. // *********************************************************************************** doEvent
  258.  
  259. void    doEvents(EventRecord *eventStrucPtr)
  260. {
  261.     WindowPartCode    partCode;
  262.     WindowRef                windowRef;
  263.     DialogRef                dialogRef;
  264.     SInt16                    itemHit;
  265.     SInt8                        charCode;
  266.     ControlRef            controlRef;
  267.     UInt32                    finalTicks;
  268.  
  269.     switch(eventStrucPtr->what)
  270.     {
  271.         case kHighLevelEvent:
  272.             AEProcessAppleEvent(eventStrucPtr);
  273.             break;
  274.  
  275.         case mouseDown:
  276.             partCode = FindWindow(eventStrucPtr->where,&windowRef);
  277.  
  278.             switch(partCode)
  279.             {
  280.                 case inMenuBar:
  281.                     doMenuChoice(MenuSelect(eventStrucPtr->where));
  282.                     break;
  283.  
  284.                 case inContent:
  285.                     if(IsDialogEvent(eventStrucPtr))
  286.                         if(DialogSelect(eventStrucPtr,&dialogRef,&itemHit))
  287.                             if(itemHit == iButtonEnter)
  288.                             {
  289.                                 doAcceptNewRecord();
  290.                                 doClearAllFields();
  291.                             }
  292.                             else if(itemHit == iButtonClear)
  293.                                 doClearAllFields();
  294.                     doAdjustCursor(windowRef);
  295.                     break;
  296.  
  297.                 case inDrag:
  298.                     DragWindow(windowRef,eventStrucPtr->where,NULL);
  299.                     doAdjustCursor(windowRef);
  300.                     break;
  301.  
  302.                 case inGoAway:
  303.                     if(TrackGoAway(windowRef,eventStrucPtr->where))
  304.                         gDone = true;
  305.                     break;
  306.             }
  307.             break;
  308.  
  309.         case keyDown:
  310.             charCode = eventStrucPtr->message & charCodeMask;
  311.  
  312.             if((charCode == kReturn) || (charCode == kEnter))
  313.             {
  314.                 GetDialogItemAsControl(gDialogRef,iButtonEnter,&controlRef);
  315.                 HiliteControl(controlRef,kControlButtonPart);
  316.                 Delay(8,&finalTicks);
  317.                 HiliteControl(controlRef,kControlEntireControl);
  318.                 doAcceptNewRecord();
  319.                 doClearAllFields();
  320.                 return;
  321.             }
  322.  
  323.             if((eventStrucPtr->modifiers & cmdKey) != 0)
  324.             {
  325.                 if(charCode == 'X' || charCode == 'x' ||    charCode == 'C' || charCode == 'c' ||
  326.                         charCode == 'V' || charCode == 'v')
  327.                 {
  328.                     HiliteMenu(mEdit);
  329.                     DialogSelect(eventStrucPtr,&dialogRef,&itemHit);
  330.                     Delay(4,&finalTicks);
  331.                     HiliteMenu(0);
  332.                 }
  333.                 else
  334.                 {
  335.                     doMenuChoice(MenuEvent(eventStrucPtr));
  336.                 }
  337.                 return;
  338.             }
  339.  
  340.             DialogSelect(eventStrucPtr,&dialogRef,&itemHit);
  341.             if(charCode == kTab)
  342.                 doAdjustCursor(GetDialogWindow(gDialogRef));
  343.             break;
  344.  
  345.         case autoKey:
  346.             if((eventStrucPtr->modifiers & cmdKey) == 0)
  347.                 DialogSelect(eventStrucPtr,&dialogRef,&itemHit);
  348.             break;
  349.  
  350.         case updateEvt:
  351.         case activateEvt:
  352.             DialogSelect(eventStrucPtr,&dialogRef,&itemHit);
  353.             break;
  354.  
  355.         case osEvt:
  356.             switch((eventStrucPtr->message >> 24) & 0x000000FF)
  357.             {
  358.                 case suspendResumeMessage:
  359.                     gInBackground = (eventStrucPtr->message & resumeFlag) == 0;
  360.                     if(!gInBackground)
  361.                         SetThemeCursor(kThemeArrowCursor);
  362.                     break;
  363.                     
  364.                 case mouseMovedMessage:
  365.                     doAdjustCursor(GetDialogWindow(gDialogRef));
  366.                     break;
  367.             }
  368.             break;
  369.     }
  370. }
  371.  
  372. // ****************************************************************************** doMenuChoice
  373.  
  374. void  doMenuChoice(SInt32 menuChoice)
  375. {
  376.     MenuID                menuID;
  377.     MenuItemIndex    menuItem;
  378.  
  379.     menuID     = HiWord(menuChoice);
  380.     menuItem = LoWord(menuChoice);
  381.  
  382.     if(menuID == 0)
  383.         return;
  384.  
  385.     switch(menuID)
  386.     {
  387.         case mAppleApplication:
  388.             if(menuItem == iAbout)
  389.                 SysBeep(10);
  390.             break;
  391.  
  392.         case mFile:
  393.             if(menuItem == iQuit)
  394.                 gDone = true;
  395.             break;
  396.  
  397.         case mEdit:
  398.             switch(menuItem)
  399.             {
  400.                 case iCut:
  401.                     DialogCut(gDialogRef);
  402.                     break;
  403.  
  404.                 case iCopy:
  405.                     DialogCopy(gDialogRef);
  406.                     break;
  407.  
  408.                 case iPaste:
  409.                     DialogPaste(gDialogRef);
  410.                     break;
  411.  
  412.                 case iClear:
  413.                     DialogDelete(gDialogRef);
  414.                     break;
  415.             }
  416.             break;
  417.     }
  418.  
  419.     HiliteMenu(0);
  420. }
  421.  
  422. // ***************************************************************************** doCopyPString
  423.  
  424. void  doCopyPString(Str255 sourceString,Str255 destinationString)
  425. {
  426.     SInt16    stringLength;
  427.  
  428.     stringLength = sourceString[0];
  429.     BlockMove(sourceString + 1,destinationString + 1,stringLength);
  430.     destinationString[0] = stringLength;
  431. }
  432.  
  433. // ****************************************************************************** doTodaysDate
  434.  
  435. void  doTodaysDate(void)
  436. {
  437.     UInt32            rawSeconds;
  438.     Str255            dateString;
  439.     ControlRef    controlRef;
  440.  
  441.     GetDateTime(&rawSeconds);
  442.     DateString(rawSeconds,longDate,dateString,NULL);
  443.  
  444.     GetDialogItemAsControl(gDialogRef,iStaticTextTodaysDate,&controlRef);
  445.     SetControlData(controlRef,kControlEntireControl,kControlStaticTextTextTag,dateString[0],
  446.                                  &dateString[1]);
  447. }
  448.  
  449. // ************************************************************************* doAcceptNewRecord
  450.  
  451. void  doAcceptNewRecord(void)
  452. {
  453.     SInt16            theType;
  454.     Handle            theHandle;
  455.     Rect                theRect;
  456.     Str255            titleString, quantityString, valueString, dateString;
  457.     ControlRef    controlRef;
  458.  
  459.     GetDialogItem(gDialogRef,iEditTextTitle,&theType,&theHandle,&theRect);
  460.     GetDialogItemText(theHandle,titleString);
  461.  
  462.     GetDialogItem(gDialogRef,iEditTextQuantity,&theType,&theHandle,&theRect);
  463.     GetDialogItemText(theHandle,quantityString);
  464.  
  465.     GetDialogItem(gDialogRef,iEditTextValue,&theType,&theHandle,&theRect);
  466.     GetDialogItemText(theHandle,valueString);
  467.  
  468.     GetDialogItem(gDialogRef,iEditTextDate,&theType,&theHandle,&theRect);
  469.     GetDialogItemText(theHandle,dateString);
  470.     
  471.     if(titleString[0] == 0 || quantityString[0] == 0 || valueString[0] == 0 || 
  472.          dateString[0] == 0)
  473.     {
  474.         SysBeep(10);
  475.         return;
  476.     }
  477.  
  478.     GetDialogItemAsControl(gDialogRef,iStaticTextTitle,&controlRef);
  479.     SetControlData(controlRef,kControlEntireControl,kControlStaticTextTextTag,titleString[0],
  480.                                  &titleString[1]);
  481.     Draw1Control(controlRef);
  482.  
  483.     GetDialogItemAsControl(gDialogRef,iStaticTextQuantity,&controlRef);
  484.     SetControlData(controlRef,kControlEntireControl,kControlStaticTextTextTag,quantityString[0],
  485.                                  &quantityString[1]);
  486.     Draw1Control(controlRef);
  487.  
  488.     doUnitAndTotalValue(valueString,quantityString);
  489.  
  490.     doDate(dateString);
  491. }
  492.  
  493. // *********************************************************************** doUnitAndTotalValue
  494.  
  495. void  doUnitAndTotalValue(Str255 valueString, Str255 quantityString)
  496. {
  497.     Handle                        itl4ResourceHdl;
  498.     SInt32                        numpartsOffset;
  499.     SInt32                        numpartsLength;
  500.     NumberParts                *numpartsTablePtr;
  501.     Str255                        formatString = "\p'$'###,###,###.00;'Valueless';'Valueless'";
  502.     NumFormatString        formatStringRec;
  503.     Str255                        formattedNumString;
  504.     extended80                value80Bit;
  505.     SInt32                        quantity;
  506.     double                        valueDouble;
  507.     FormatResultType    result;
  508.     ControlRef                controlRef;
  509.  
  510.     GetIntlResourceTable(smSystemScript,iuNumberPartsTable,&itl4ResourceHdl,&numpartsOffset,
  511.                                              &numpartsLength);
  512.     numpartsTablePtr = (NumberPartsPtr) ((SInt32) *itl4ResourceHdl + numpartsOffset);
  513.  
  514.     StringToFormatRec(formatString,numpartsTablePtr,&formatStringRec);
  515.  
  516.     StringToExtended(valueString,&formatStringRec,numpartsTablePtr,&value80Bit);
  517.     ExtendedToString(&value80Bit,&formatStringRec,numpartsTablePtr,formattedNumString);
  518.  
  519.     GetDialogItemAsControl(gDialogRef,iStaticTextUnitValue,&controlRef);
  520.     SetControlData(controlRef,kControlEntireControl,kControlStaticTextTextTag,
  521.                                  formattedNumString[0],&formattedNumString[1]);
  522.     Draw1Control(controlRef);
  523.  
  524.     StringToNum(quantityString,&quantity);
  525.  
  526.     valueDouble = x80tod(&value80Bit);
  527.     valueDouble = valueDouble * quantity;
  528.     dtox80(&valueDouble,&value80Bit);
  529.  
  530.     result = ExtendedToString(&value80Bit,&formatStringRec,numpartsTablePtr,
  531.                                                         formattedNumString);
  532.  
  533.     if(result == fFormatOverflow)
  534.         doCopyPString("\p(Too large to display)",formattedNumString);
  535.  
  536.     GetDialogItemAsControl(gDialogRef,iStaticTextTotalValue,&controlRef);
  537.     SetControlData(controlRef,kControlEntireControl,kControlStaticTextTextTag,
  538.                                  formattedNumString[0],&formattedNumString[1]);
  539.     Draw1Control(controlRef);
  540. }
  541.  
  542. // ************************************************************************************ doDate
  543.  
  544. void  doDate(Str255 dateString)
  545. {
  546.     SInt32                lengthUsed;
  547.     LongDateRec        longDateTimeRec;
  548.     LongDateTime    longDateTimeValue;
  549.     ControlRef        controlRef;
  550.  
  551.     longDateTimeRec.ld.hour = 0;
  552.     longDateTimeRec.ld.minute = 0;
  553.     longDateTimeRec.ld.second = 0;
  554.  
  555.     StringToDate((Ptr) dateString + 1,dateString[0],&gDateCacheRec,&lengthUsed,
  556.                              &longDateTimeRec);
  557.  
  558.     LongDateToSeconds(&longDateTimeRec,&longDateTimeValue);
  559.     LongDateString(&longDateTimeValue,longDate,dateString,NULL);
  560.  
  561.     GetDialogItemAsControl(gDialogRef,iStaticTextDate,&controlRef);
  562.     SetControlData(controlRef,kControlEntireControl,kControlStaticTextTextTag,dateString[0],
  563.                                  &dateString[1]);
  564.     Draw1Control(controlRef);
  565. }
  566.  
  567. // **************************************************************************** doAdjustCursor
  568.  
  569. void  doAdjustCursor(WindowRef windowRef)
  570. {
  571.     GrafPtr        oldPort;
  572.     RgnHandle    arrowRegion,iBeamRegion;
  573.     SInt16        currentFocusItem;
  574.     SInt16        theType;
  575.     Handle        theHandle;
  576.     Rect            iBeamRect;
  577.     Point            mouseXY;
  578.  
  579.     GetPort(&oldPort);
  580.     SetPortWindowPort(windowRef);
  581.  
  582.     arrowRegion = NewRgn();
  583.     iBeamRegion = NewRgn();
  584.  
  585.     SetRectRgn(arrowRegion,-32768,-32768,32767,32767);
  586.  
  587.     currentFocusItem = GetDialogKeyboardFocusItem(gDialogRef);
  588.     GetDialogItem(gDialogRef,currentFocusItem,&theType,&theHandle,&iBeamRect);
  589.  
  590.     LocalToGlobal(&topLeft(iBeamRect));
  591.     LocalToGlobal(&botRight(iBeamRect));    
  592.  
  593.     RectRgn(iBeamRegion,&iBeamRect);
  594.     DiffRgn(arrowRegion,iBeamRegion,arrowRegion);
  595.     
  596.     GetMouse(&mouseXY);
  597.     LocalToGlobal(&mouseXY);
  598.  
  599.     if(PtInRgn(mouseXY,iBeamRegion))
  600.     {
  601.         SetThemeCursor(kThemeIBeamCursor);
  602.         CopyRgn(iBeamRegion,gCursorRegionHdl);
  603.     }
  604.     else
  605.     {
  606.         SetThemeCursor(kThemeArrowCursor);
  607.         CopyRgn(arrowRegion,gCursorRegionHdl);
  608.     }
  609.  
  610.     DisposeRgn(arrowRegion);
  611.     DisposeRgn(iBeamRegion);
  612.  
  613.     SetPort(oldPort);
  614. }
  615.  
  616. // ************************************************************************** doClearAllFields
  617.  
  618. void  doClearAllFields(void)
  619. {
  620.     SInt16            a;
  621.     ControlRef    controlRef;
  622.     Str255            theString = "\p";
  623.  
  624.     for(a = iEditTextTitle;a <= iEditTextDate;a++)
  625.     {
  626.         GetDialogItemAsControl(gDialogRef,a,&controlRef);
  627.         SetControlData(controlRef,kControlEntireControl,kControlEditTextTextTag,theString[0],
  628.                                  &theString[1]);
  629.         Draw1Control(controlRef);
  630.  
  631.         if(a == iEditTextTitle)
  632.             SetKeyboardFocus(GetDialogWindow(gDialogRef),controlRef,kControlFocusNextPart);
  633.     }
  634. }
  635.  
  636. // ***************************************************************************** numericFilter
  637.  
  638. ControlKeyFilterResult  numericFilter(ControlRef controlRef,SInt16* keyCode,SInt16 *charCode,
  639.                                                                             EventModifiers *modifiers)
  640. {
  641.     if(((char) *charCode >= '0') && ((char) *charCode <= '9') || (char) *charCode == '.' ||
  642.          (BitTst(modifiers,15 - cmdKeyBit)))
  643.     {
  644.         return kControlKeyFilterPassKey;
  645.     }
  646.  
  647.     switch(*charCode)
  648.     {
  649.         case kLeftArrow:
  650.         case kRightArrow:
  651.         case kUpArrow:
  652.         case kDownArrow:
  653.         case kBackspace:
  654.         case kDelete:
  655.             return kControlKeyFilterPassKey;
  656.             break;
  657.     }
  658.  
  659.     SysBeep(10);
  660.     return kControlKeyFilterBlockKey;
  661. }
  662.  
  663. // ********************************************************************************** helpTags
  664.  
  665. void  helpTags(void)
  666. {
  667.     HMHelpContentRec    helpContent;
  668.     SInt16                        a;
  669.     static SInt16            itemNumber[7] = { 1,3,21,22,23,24,25 };
  670.     ControlRef                controlRef;
  671.  
  672.     memset(&helpContent,0,sizeof(helpContent));
  673.  
  674.     HMSetTagDelay(5);
  675.     HMSetHelpTagsDisplayed(true);
  676.     helpContent.version = kMacHelpVersion;
  677.     helpContent.tagSide = kHMOutsideTopCenterAligned;
  678.  
  679.     helpContent.content[kHMMinimumContentIndex].contentType = kHMStringResContent;
  680.     helpContent.content[kHMMinimumContentIndex].u.tagStringRes.hmmResID = 128;
  681.  
  682.     for(a = 1;a <= 7; a++)
  683.     {
  684.         helpContent.content[kHMMinimumContentIndex].u.tagStringRes.hmmIndex = a;
  685.         GetDialogItemAsControl(gDialogRef,itemNumber[a - 1],&controlRef);
  686.         HMSetControlHelpContent(controlRef,&helpContent);
  687.     }
  688. }
  689.  
  690. // *******************************************************************************************
  691.